package com.hc.fdkgoods.dao;

import com.hc.fdkgoods.db.tables.ForwarderSupplier;
import com.hc.fdkgoods.db.tables.records.ForwarderSupplierRecord;
import com.hc.fdkgoods.vo.ForwarderSupplierGroupVO;
import com.hc.fdkgoods.vo.ForwarderSupplierVO;
import com.hc.fdkgoods.vo.ForwarderWholeVO_1;
import com.hc.fdkgoods.vo.vo_8.ForwarderSupplierGroupListVO;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.hc.fdkgoods.db.Tables.FORWARDER_SUPPLIER;

@Repository
public class ForwarderSupplierDao extends BaseDao {
    public ForwarderWholeVO_1 queryAll() {
        List<ForwarderSupplierGroupVO> list = db.selectDistinct(ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME).from(ForwarderSupplier.FORWARDER_SUPPLIER).fetchInto(ForwarderSupplierGroupVO.class);

        for (ForwarderSupplierGroupVO data : list) {
            data.setSupplierVOList(db.select(ForwarderSupplier.FORWARDER_SUPPLIER.BUSINESS,
                    ForwarderSupplier.FORWARDER_SUPPLIER.CITY,
                    ForwarderSupplier.FORWARDER_SUPPLIER.CITY_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FLOOR,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FLOOR_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FORWARDER_SUPPLIER_ID,
                    ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME,
                    ForwarderSupplier.FORWARDER_SUPPLIER.MARKET_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.MARKET,
                    ForwarderSupplier.FORWARDER_SUPPLIER.SUPPLIER_NAME).from(ForwarderSupplier.FORWARDER_SUPPLIER).where(ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME.eq(data.getGroupName())).fetchInto(ForwarderSupplierVO.class));
        }
        ForwarderWholeVO_1 f = new ForwarderWholeVO_1();
        f.setList(list);
        return f;

    }

    public ForwarderSupplierGroupListVO querySupplierGroupList() {
        List<ForwarderSupplierGroupVO> list = db.selectDistinct(ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME).from(ForwarderSupplier.FORWARDER_SUPPLIER).fetchInto(ForwarderSupplierGroupVO.class);

        for (ForwarderSupplierGroupVO data : list) {
            data.setSupplierVOList(db.select(ForwarderSupplier.FORWARDER_SUPPLIER.BUSINESS,
                    ForwarderSupplier.FORWARDER_SUPPLIER.CITY,
                    ForwarderSupplier.FORWARDER_SUPPLIER.CITY_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FLOOR,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FLOOR_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.FORWARDER_SUPPLIER_ID,
                    ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME,
                    ForwarderSupplier.FORWARDER_SUPPLIER.MARKET_CODE,
                    ForwarderSupplier.FORWARDER_SUPPLIER.MARKET,
                    ForwarderSupplier.FORWARDER_SUPPLIER.SUPPLIER_NAME).from(ForwarderSupplier.FORWARDER_SUPPLIER).where(ForwarderSupplier.FORWARDER_SUPPLIER.GROUP_NAME.eq(data.getGroupName())).fetchInto(ForwarderSupplierVO.class));
        }
        ForwarderSupplierGroupListVO res = new ForwarderSupplierGroupListVO();
        res.setList(list);
        return res;
    }

}
